
using System;
using System.Drawing;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using bjeschool_csharp.Model;

namespace bjeschool
{
	public partial class LoginController : UIViewController
	{
		[Connect("loginName")]
		public UITextField loginName { 
			get {
				return ((UITextField) (this.GetNativeField("loginName")));
			}
			set {
				this.SetNativeField("loginName", value);
			} 
		}
		
		[Connect("loginPassword")]
		private UITextField loginPassword { 
			get {
				return ((UITextField) (this.GetNativeField("loginPassword")));
			}
			set {
				this.SetNativeField("loginPassword", value);
			} 
		}

		[Action ("OnLogin")]
		void OnLogin ()
		{
			if (loginName.Text == "sgzhouxia" || loginName.Text == "sgzhouting") {
				AppDelegate.loginuser = new M_Teacher ();
				AppDelegate.app.Window.RootViewController = new FirstPageController ("FirstPageController");
			} else if (loginName.Text.Substring (0, 4) == "sg21") {
				AppDelegate.loginuser = new M_Student ();
				AppDelegate.app.Window.RootViewController = new FirstPageController ("FirstPageStudent");
			} else {
				AppDelegate.loginuser = new M_Parent ();
				AppDelegate.app.Window.RootViewController = new FirstPageController ("FirstPageParent");
			}
			//NSObject initView = UIStoryboard.FromName("MainStoryBoard", null).InstantiateInitialViewController();
			//AppDelegate.app.Window.RootViewController = initView as UIViewController;
		}

		public LoginController () : base ("LoginController", null)
		{
		}

		public override void DidReceiveMemoryWarning ()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning ();

			// Release any cached data, images, etc that aren't in use.
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// Perform any additional setup after loading the view, typically from a nib.
		}
		
		public override void ViewDidUnload ()
		{
			base.ViewDidUnload ();
			
			// Clear any references to subviews of the main view in order to
			// allow the Garbage Collector to collect them sooner.
			//
			// e.g. myOutlet.Dispose (); myOutlet = null;
			
			ReleaseDesignerOutlets ();
		}
		
		public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
		{
			// Return true for supported orientations
			return true;
		}
	}
}

